<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="sealte.mynode.pojo.*"%>
<%@ page import="sealte.mynode.bean.*"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>MyNode</title>
<link rel="stylesheet" type="text/css" href="css/div2.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/index_jsp.js"></script>
</head>
<body>
	<%
		User user = (User) session.getAttribute("user");
		int user_id = user.getId();
		String user_name = user.getName();
		String user_email = user.getEmail();
		String idStr = request.getParameter("id");
		int id = Integer.parseInt(idStr);
		EssayBean eb = new EssayBean();
		Essay essay = eb.getInfoById(id);
		CommentBean cb = new CommentBean();
		List<Comment> all = cb.listAllByEssayId(essay.getId());
	%>
	<center>
		<h1><%=user_name.toUpperCase()%>'s MyNode
		</h1>
		<br /> Email:<%=user_email%>
		#--# <a href="UserLogout?id=<%=user_id%>">Logout</a> #--# <a href="home.jsp">Back</a>
		<div>
			<table>
				<tr>
					<th align="center">AUTHOR:<%=essay.getAuthor() %>/<%=essay.getAuthorId() %></th>
					<th align="center">WriteTime:<%=essay.getWriteTime() %></th>
					<th align="center">ModifyTime:<%=essay.getModifyTime() %></th>
				</tr>
				<tr>
					<td align="center" colspan="3"><h3><%=essay.getTitle() %></h3></td>
				</tr>
				<tr>
					<td align="left" colspan="3">
						<%=essay.getContent()%>
					</td>
				</tr>
			</table>
		</div>
		
		<div>
		<table>
		<tr><th align="left">Comment:</th></tr>
		<%
			if(null!=all && !all.isEmpty()){
				Iterator<Comment> iter = all.iterator();
				while(iter.hasNext()){
					Comment com = (Comment)iter.next();
					out.println("<tr><td>"+com.getParent()+"/"+com.getUser()+"</td><td>"+com.getWriteTime()+"</td><td>"
								+com.getModifyTime()+"</td></tr>");
					out.println("<tr><td colspan=\"3\" align=\"left\">"+com.getContent()+"</td></tr>");
				}
			}else{
		%>
		<tr><td align="center">There is no comment for this essay now!</td></tr>
		<%
			}
		%>
		</table>
		</div>
		
		<div>
			<form action="CommentAddNew" method="POST">
				<input type="hidden" name="essay_id" value="<%=essay.getId()%>"/>
				<input type="hidden" name="user_id" value="<%=user_id%>"/>
				<input type="hidden" name="parent_id" value="0"/>
				<table>
				<tr><th align="left">Your Comment:</th></tr>
				<tr>
				<td align="left">
				<textarea name="content" rows="3" cols="50"></textarea>
				<br/>
				<input type="submit" value="Submit"/>
				</td>
				</tr>
				</table>
			</form>
		</div>
		
		<div>
			<table>
				<tr>
					<th colspan="2" align="center">Current Server</th>
				</tr>
				<tr>
					<td align="right">Session:</td>
					<td align="left"><%=session.getId()%></td>
				</tr>
				<tr>
					<td align="right">IP:</td>
					<td align="left"><%=java.net.InetAddress.getLocalHost()%></td>
				</tr>
				<tr>
					<td align="right">TempDir:</td>
					<td align="left"><%=System.getProperty("java.io.tmpdir")%></td>
				</tr>
			</table>
		</div>
	</center>
</body>
</html>